<template>
 <view class="filling" style="bottom:10vh">
    <view @click="navTo('canCode/takeOut')">
      <text>外卖</text>
      <text>加注</text>
    </view>
    <view @click="scanCode()">
      <text>扫码</text>
      <text>加注</text>
    </view>
  </view>
</template>

<script setup lang="ts">
  import { getDriverID } from '@/stores/driverID';
  import { navTo } from '@/utils/navigator';
  import { toPublish } from '@mqtt';
  import { scanQRCode } from '@/utils/wechat.jssdk';
  import { ref } from 'vue';
  const driver_id = getDriverID();
  const repeat = ref(true); //放重复点击
  const props = defineProps({
    orderJID: {
      type: Number || String,
      default: 0,
    },
  });
  function scanCode() {
    if (!uni.getStorageSync('storage_key').id || !driver_id) {
      uni.setStorageSync('storage', 'user');
      uni.reLaunch({
        url: '/pages/login/login',
      });
      return;
    }
    // uni.setStorageSync('fillingID', 36);
    // uni.navigateTo({
    //   url: '/pages/canCode/KeyFill?id=4',
    // });
    // return;
    const storage_key = uni.getStorageSync('is_checker');
    scanQRCode((res : any) => {
      const orderIDs = res.resultStr.split('fill_id=')[1];
      if (orderIDs) {
        uni.setStorageSync('fillingID', orderIDs);
        if (props.orderJID) {
          uni.navigateTo({
            url: '/pages/canCode/canState?id=' + props.orderJID,
          });
        } else if (storage_key != '0') {
          uni.reLaunch({
            url: '/pages/tester/selectIdentity',
          });
        } else {
          viewUser(orderIDs);
        }
      } else {
        alert('请扫描正确的二维码进行加注');
      }
    });
  }
  function viewUser(num) {
    if (!repeat.value) {
      return;
    }
    repeat.value = false;
    const payload = {
      fill_id: num.toString(),
      driver_id,
    };
    toPublish('driver/getRole', payload, (obj : any) => {
      const { data } = obj;
      repeat.value = true;
      uni.navigateTo({
        url: data.page + '',
      });
    });
  }
</script>
<style scoped lang="less">
  .filling {
    width: 170rpx;
    height: 380rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: fixed;
    bottom: 8vh;
    right: 2.5%;
    z-index: 99;

    view:nth-of-type(1) {
      // background: #1b91ff;
      background-image: url(../../static/filling/ss.png);
      background-repeat: no-repeat;
      background-position: center;
      background-size: cover;
      border-radius: 5px;
      box-shadow: 0px 4px 8px 0px rgba(16, 108, 194, 1);
    }

    view:nth-of-type(2) {
      // background: #fd9b00;
      background-image: url(../../static/filling/yy.png);
      background-repeat: no-repeat;
      background-position: center;
      background-size: cover;
      border-radius: 5px;
      box-shadow: 0px 4px 8px 0px rgba(170, 105, 3, 1);
    }

    view {
      width: 170rpx;
      height: 170rpx;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: space-around;
      border-radius: 5px;
      padding: 20rpx 0px;
      box-sizing: border-box;

      image {
        width: 170rpx;
        height: 170rpx;
      }

      text {
        font-size: 42rpx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #ffffff;
        line-height: 44rpx;
        letter-spacing: 2px;
      }
    }
  }

  .fabs {
    position: fixed;
    bottom: 8vh;
    right: 2.5%;
    z-index: 99;
  }
</style>
<style>
  .fabs>>>.uni-fab__content--other-platform {
    box-shadow: 0 1px 5px 2px rgba(0, 0, 0, 0);
    bottom: 100px;
  }

  .fabs>>>.uni-fab--rightBottom {
    bottom: 100px !important;
  }
</style>